/*
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */
package au.com.domlogic.helloPVCWorld.builder;

import au.com.domlogic.pvc.core.element.ElementMoldBuilder;
import au.com.domlogic.pvc.xhtml.attr.ClassAttrMold;
import au.com.domlogic.pvc.xhtml.element.H1ElementMold;
import java.util.Locale;

/**
 * This builder uses an interface into a data model to source its content.  In
 * a productiona scenario, a developer may inject the data model into this class
 * using Spring Framework or similar technology, but for the purpose of this demo,
 * I have just initialised the class with an implementation in the constructor.
 * 
 * @author Domenic Figliomeni
 */
public class ExampleHeadingMoldBuilder implements ElementMoldBuilder {

    private ExampleHeadingDataModel mold;
    private Locale locale;

    public ExampleHeadingMoldBuilder() {
        //I could inject this with Spring or other
        this.mold = new ExampleHeadingDataModelImpl();
    }

    @Override
    public H1ElementMold buildElementMold() {
        H1ElementMold exampleHeading = new H1ElementMold();
        String textContent = mold.getText(locale);
        ClassAttrMold defaultClass = new ClassAttrMold("example-heading");
        exampleHeading.addAttrMold(defaultClass);
        if (mold.isImportant()) {
            textContent += "!";
            ClassAttrMold importantClass = new ClassAttrMold("important-example-heading");
            exampleHeading.addAttrMold(importantClass);
        }
        exampleHeading.setContent(textContent);
        return exampleHeading;
    }

    public Locale getLocale() {
        return locale;
    }

    public void setLocale(Locale locale) {
        this.locale = locale;
    }
}
